<?php
namespace app\controllers;

use app\logic\CategoryLogic;
use Yii;

class CategoryController extends BaseController
{
	public function actionIndex()
	{
        $this->response(time());
	}

    /**
     * 获取分类
     * @apiDescription   by Jim
     * @api              {post} /category/get-category 获取分类
     * @apiName          get-category
     * @apiVersion       1.0.0
     * @apiParam {int} category_id 不传或传0默认是一级分类
     * @apiGroup         Category
     * @apiSampleRequest /category/get-category?flagsign=1
     * @apiSuccessExample {json} 获取成功
     * [{
            "category_id": 12, // int 分类Id
            "category_pic": "xxx", // 分类图片
            "category_name": "xxx", // 分类名
      }]
     * @apiError         20000    获取失败
     */
    public function actionGetCategory(){
        $category_id = $this->getQueryparams('category_id',0);
        $categoryLogic = new CategoryLogic();
        $category = $categoryLogic->getCategory($category_id);
        foreach($category AS &$item){
            $item['category_pic'] = Yii::$app->params['pic_domain'].$item['category_pic'];
        }
        $this->response($category);
    }

}